<html>
<head>
	<title>My Form</title>
	<link href="<?php echo  base_url();?>public/css/bootstrap.min.css" rel="stylesheet">
	<link href="<?php echo  base_url();?>public/css/bootstrap-theme.min.css" rel="stylesheet">
	<link href="<?php echo  base_url();?>public/css/style.css" rel="stylesheet">
	<script charset="utf-8" src="<?php echo  base_url();?>public/kindeditor/kindeditor-all-min.js"></script>
	<script charset="utf-8" src="<?php echo  base_url();?>public/kindeditor/lang/zh-CN.js"></script>
	<script charset="utf-8" src="<?php echo  base_url();?>public/js/jquery.min.js"></script>
	<script charset="utf-8" src="<?php echo  base_url();?>public/js/jquery.upload.js"></script>
</head>
<body>
	<div class="container">
		<h1><?php echo $title?>文章</h1>
		<div class="row">
  			<div class="col-md-9 col-md-offset-1">  			
  				<form class="form-horizontal" action="" method="POST">
					<div class="form-group">
					<label class="col-sm-2 control-label"><b class="error">*</b>标题</label>
					    <div class="col-sm-4">
					      	<input type="text" class="form-control" name="title" value="<?php echo set_value('title',$article->title)?>">
							<?php echo form_error('title');?>
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label"><b class="error">*</b>分类</label>
					    <div class="col-sm-3">
					      	<select class="form-control" name="catalog_id">
					      		<option value="">请选择一个分类</option>
					      		<?php foreach($catalogs as $c) {?>
					      			<option <?php echo set_select('catalog_id',$c->id,$c->id==$article->catalog_id); ?> value="<?=$c->id?>"><?php echo $c->name?></option>
					      		<?php }?>
					      	</select>
					      	<?php echo form_error('catalog_id');?>
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label"><b class="error">*</b>图片</label>
					    <div class="col-sm-5">
					      	<input type="text" class="form-control" id="img" name="img" value="<?php echo set_value('img',$article->img)?>">
					      	<a id="upload" href="#">上传文件</a>
							<?php echo form_error('img');?>
					    </div>
					    <div class="col-sm-5" id="preview">
						</div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label"><b class="error">*</b>描述</label>
					    <div class="col-sm-10">
					      	<textarea class="form-control"  name="desc"><?php echo set_value('desc',$article->desc)?></textarea>
							<?php echo form_error('desc');?>
					    </div>
					</div>
					<div class="form-group">
					    <label class="col-sm-2 control-label"><b class="error">*</b>内容</label>
					    <div class="col-sm-10">
					      	<textarea  class="form-control" id="content" name="content"><?php echo set_value('content',$article->content)?></textarea>
							<?php echo form_error('content');?>
					    </div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label"></label>
					    <div class="col-sm-10">
	      					<input type="submit" class="btn btn-success ">
	      					<a href="<?php echo site_url('admin/article/index') ?>">返回</a>
	      				</div>
	      			</div>
				</form>  			
	  		</div>		
		</div>
	</div>
</body>
</html>
<script>
	KindEditor.create('#content');
	$("#upload").click(function(){
		$.upload({
	        url: '<?php echo site_url("admin/util/upload")?>', 
	        fileName: 'file', 
	        dataType: 'text',
	        onSend: function() {
	            return true;
	        },
	        onComplate: function(data) {
	        	if(data.indexOf("upload") >= 0){	//js判断一个字符是否存在
	        		$("#img").val(data);
	        		$("#preview").html('<img style="height:80px;" src="<?php echo base_url()?>'+data+'" />')
				}	
	        }
		});
	})
</script>